package com.atguigu.gulimall.product.bn.myuntil;

import java.util.HashMap;
import java.util.Map;

/**
 * @NAME: UrlMap
 * @USER: wjj
 * @DATE: 2023/6/12
 * @TIME: 10:52
 * @DAY_NAME_FULL: 星期一
 * @PROJECT_NAME: SpringMVC
 */
public class UrlMap {
    public static void main(String[] args) {
        UrlMap urlMap = new UrlMap();
        String str1="tOntBulT3xWPw dbbT5ZJ43QzMJP4ZBmV9jQmiH bgUpQ1v9CXQTml34 T1PX1gd6nDqIp6 sNQN0c9dSruVood2DUd16aUL3rw086jzdM36wymsFZ2X8Mxhh0DoSwwZhyTHr wJM5ipMBMHCIYUwoBURqbLNNY2n apvIvJd7A=";
        String str2="tOntBulT3xWPw+dbbT5ZJ43QzMJP4ZBmV9jQmiH+bgUpQ1v9CXQTml34+T1PX1gd6nDqIp6+sNQN0c9dSruVood2DUd16aUL3rw086jzdM36wymsFZ2X8Mxhh0DoSwwZhyTHr+wJM5ipMBMHCIYUwoBURqbLNNY2n+apvIvJd7A";
        System.out.println(str1.replace(" ","+")==str2);

    }

    public Map<String,String> urlMap(String url){
        Map<String, String> urlMap = new HashMap<>();
        if (url == null) {
            urlMap.put("encrypt", "请求url为空");
        }else {
            String[] split1 = url.split("&");
//        System.out.println(Arrays.toString(split1));
            for (String s : split1) {
                Integer count = UrlMap.count(s);
                if (count>1){
                    int i = s.indexOf("=");

                    urlMap.put(s.substring(0,i),s.substring(i+1));
                }else {

                    String[] split2 = s.split("=");
                    urlMap.put(split2[0],split2[1]);
                }


            }
        }

        return urlMap;
    }

    public static Integer count(String uString){
        int count=0;
        int index = uString.indexOf("=");
        while (index!=-1){
            count++;
            index = uString.indexOf("=", index + 1);
        }
        return count;
    }
}
